package com.tanjie.blackbean.iot.demo;

import com.tanjie.blackbean.iot.demo.support.OnMessageCallback;
import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @Author tanjie
 * @Date 2022/6/20 下午3:05 周一
 **/
@Component
public class ApplicationStartup implements ApplicationRunner {

    @Resource
    MqttClient mqttClient;

    @Override
    public void run(ApplicationArguments args) throws MqttException {
        // 设置回调
        mqttClient.setCallback(new OnMessageCallback());
        mqttClient.subscribe("blackbean/hello", 2);
    }

}
